<?php


namespace App\Http\observer;


use App\Models\CouponLog;
use App\Models\User;

class CouponLogObserve
{
    public function created(CouponLog $couponLog)
    {
        if($couponLog["invite_uid"]==0){
            
            $couponLog["invite_uid"]=$couponLog["uid"];
        }
        
        $user=User::where("id",$couponLog["invite_uid"])->first();
        if(!$user){
            return;
        }
        if ($user["coupon"]==""){
            User::where("id",$couponLog["invite_uid"])->update(["coupon"=>$couponLog["price"]]);
        }else{
            $user->increment("coupon",$couponLog["price"]);
        }
    }
}
